package resources;

import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;

/** Sound effects. */
public enum Sound {
    TREASURE_JEWEL("pickup01.wav"),
    MAGE_DEATH("death04.wav"),
    FIREBALL_DEATH("fireballcollide01.wav"),
    EYEBALL_SPAWN("monsterspawn01.wav"),
    EYEBALL_DEATH("death01.wav"),
    TELEPORT("teleport03.wav");

    /** */
    private final String filename;
    /** */
    private AudioClip audioClip;

    /** @param newFilename - the filename. */
    private Sound(final String newFilename) {
        filename = newFilename;
    }

    /** @return the filename. */
    public String getFilename() {
        return filename;
    }

    /** @return the audio clip. */
    public AudioClip getAudioClip() {
        return audioClip;
    }

    /**
     * Loads all the sounds in this enumeration.
     * 
     * @param applet - used to load the sounds.
     */
    public static void loadAll(final Applet applet) {
        for (Sound s : values()) {
            URL url = Sprite.class.getResource("/sounds/" + s.filename);
            System.out.println("Loading sound: " + url);
            s.audioClip = applet.getAudioClip(url);
        }
    }

    /** Play the sound. */
    public void play() {
        audioClip.play();
    }
}
